<!-- 会员 -->
<template>
  <div class="app-container">
    <!-- 检索 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="会员名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入会员名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >
          搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <!-- 表头操作 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="() => this.$refs.handleDialogRef.openDialog()"
          v-hasPermi="['system:role:add']"
        >
          新增
        </el-button>
      </el-col>
    </el-row>

    <!-- 表格 -->
    <el-table v-loading="loading" :data="tableList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="会员名称" prop="name" align="center" />
      <el-table-column label="地址" prop="address" align="center" />
      <el-table-column label="联系方式" prop="phone" align="center" />
      <el-table-column label="邮箱" prop="mail" align="center" />
      <el-table-column label="网站" prop="website" align="center" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:role:edit']"
          >
            修改
          </el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:role:edit']"
          >
            详情
          </el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:role:remove']"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <HandleDialog ref="handleDialogRef" @updateTable="resetQuery" />
  </div>
</template>
<script>
import { customerList, customerDelete } from "@/api/useMenu/member";
import HandleDialog from "./components/handleDialog.vue";
export default {
  name: "Member",
  components: { HandleDialog },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    /** 查询表格数据 */
    async getList() {
      this.loading = true;
      let response = await customerList(this.queryParams);
      this.tableList = response.rows;
      this.total = response.total;
      this.loading = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.handleDialogRef.openDialog("edit", row);
    },
    /** 详情按钮操作 */
    handleDetail(row) {},
    /** 删除按钮操作 */
    handleDelete(row) {
      const { id, name } = row;
      this.$modal
        .confirm('是否确认删除会员名称为"' + name + '"的数据项？')
        .then(function () {
          return customerDelete(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped></style>
